<?php

namespace App\Http\Requests\Api\User;

use App\Http\Base\BaseRequest;

/**
 * 用户登录验证
 * Class UserLoginPostRequest
 * @package App\Http\Requests\Api\User
 */
class UserLoginPostRequest extends BaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'username' => ['required','max:20','min:6','regex:/^[A-Za-z][A-Za-z1-9_-]+$/'],
            'password' => 'required|max:20|min:6',
        ];
    }

    /**
     * 自定义错误信息
     * @return array
     */
    public function messages()
    {
        return [
            'username.required' => '用户名不能为空',
            'username.max'=> '用户名长度超过20位',
            'username.regex'=> '用户名格式异常',
            'username.min'=> '用户名长度低于6位',
            'password.required'=> '密码不能为空',
            'password.max'=> '密码长度超过20位',
            'password.min'=> '密码长度低于6位',
        ];
    }
}
